package finassist.DAO;

import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import finassist.model.Entiti;
import finassist.model.EntitiType;
import finassist.model.User;
import finassist.util.HibernateUtil;

/**
 * AJ Projects
 * LoginUserManagerDAO.java
 * Purpose: Login User Database.
 *
 * @author Karthick Natarajan
 * @version 1.0 9/10/13
 */

public class LoginUserManagerDAO extends HibernateUtil {

	public List<User> getUserDetails(User user) {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<User> users = null;
		
		try {
			
			users = (List<User>)session.createSQLQuery("select * from public.fnas_user_reg_tbl where \"Username\"= "+ "'"+user.getUsername()+"'").addEntity(User.class).list();
					
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return users;
	}
	
	
public List<Entiti> getEntityDetails() {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Entiti> entitis = null;
		
		try {
			
			entitis = (List<Entiti>)session.createSQLQuery("select * from public.fnas_master_entity_tbl").addEntity(Entiti.class).list();
					
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return entitis;
	}
	
public List<EntitiType> getEntityTypes() {
	
	Session session = HibernateUtil.getSessionFactory().getCurrentSession();
	session.beginTransaction();
	List<EntitiType> entitis = null;
	
	try {
		
		entitis = (List<EntitiType>)session.createSQLQuery("select * from public.fnas_entiti_types").addEntity(EntitiType.class).list();
				
	} catch (HibernateException e) {
		e.printStackTrace();
		session.getTransaction().rollback();
	}
	session.getTransaction().commit();
	return entitis;
}
	
}
